package script.commontool
{
	import laya.display.Node;
	import laya.events.Event;
	import laya.ui.Label;
	
	import ui.prefab.NumInputPanelUI;

	public class NumerInputTool
	{
		private static var _instance:NumerInputTool;
		private static var gui:NumInputPanelUI;
		
		private var controllabel:Label;
		
		public function WaitingRespond()
		{
		}
		
		public  static function get instance():NumerInputTool
		{
			if(_instance == null)
			{
				_instance = new NumerInputTool();
				//initView();
			}
			
			return _instance;
		}
		
		private  function initView():void
		{
			gui = new NumInputPanelUI();
			for(var i:int=0;i < 10;i++)
			{
				gui.num0.on(Event.CLICK,NumerInputTool,onClickNum,[i]);
			}
			
		}
		
		public function showGui(node:Node,conlable:Label):void
		{
			if(gui == null)
			{
				gui = new NumInputPanelUI();
				
				for(var i:int=0;i < 10;i++)
				{
					gui["num" + i].on(Event.CLICK,this,onClickNum,[i]);
				}
				
				gui.delbtn.on(Event.CLICK,this,onDelnum);
			}
			
			controllabel = conlable;
			if(gui.parent != null)
				gui.removeSelf();
			
			node.addChild(gui);
			gui.x = 0;
			gui.y = 850;
		}
		
		public function hide():void
		{
			if(gui.parent != null)
				gui.removeSelf();
			
		}
		public function NumerInputTool()
		{
		}
		
		private  function onClickNum(index:int):void
		{
			if(controllabel != null)
				controllabel.text += index;
		}
		
		private  function onDelnum():void
		{
			if(controllabel != null)
			{
				if(controllabel.text.length > 0)
				{
					controllabel.text = controllabel.text.substr(0,controllabel.text.length-1);
				}
				
			}
		}
		
	}
}